/**
 * @file SystemTimer.h
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2024-10-25
 *
 * @copyright Copyright (c) 2024
 *
 */
#ifndef _SYSTEMTIMER_H
#define _SYSTEMTIMER_H

#include "stdint.h"

#define MAX_TIMER_ID (0xFFFFFFFFU)
#define MAX_DESTORY_LIST_NUM	(10)

typedef void (*SystemTimerCb)(void *);


enum SystemTimerState
{
	SYSTEM_TIMER_STOP,
	SYSTEM_TIMER_RUNNING,
	SYSTEM_TIMER_TIMEOUT,
	SYSTEM_TIMER_DESTORY,
};
typedef enum SystemTimerState SystemTimerState_t;

enum SystemTimerMode
{
	TIMER_ONESHOT_MODE,
	TIMER_PERIOD_MODE,
};
typedef enum SystemTimerMode SystemTimerMode_t;

struct SystemTimerParam
{
	void *argv;
	uint32_t id;
	SystemTimerCb cb;
	uint32_t period;
	SystemTimerMode_t mode;
};
typedef struct SystemTimerParam SystemTimerParam_t;

struct SystemTimer
{
	void *argv;
	uint32_t id;
	SystemTimerCb cb;
	uint32_t match;
	uint32_t period;
	SystemTimerMode_t mode;
	SystemTimerState_t state;
	struct SystemTimer *next;
};
typedef struct SystemTimer SystemTimer_t;

#ifdef __cplusplus
extern "C"
{
#endif

extern void SystemTimerTickUpdate(void);
extern uint32_t SystemTimerTickGet(void);
extern void SystemTimerPrint(const SystemTimer_t *timer);
extern SystemTimer_t *SystemTimerFind(const SystemTimer_t *timer, uint32_t id);
extern uint32_t SystemTimerFindIdleId(SystemTimer_t *timer);
extern SystemTimer_t *SystemTimerHeadCreate(SystemTimer_t **timer, SystemTimerParam_t *param);
extern SystemTimer_t *SystemTimerTailCreate(SystemTimer_t **timer, SystemTimerParam_t *param);
extern SystemTimer_t *SystemTimerCreate(SystemTimer_t **timer, SystemTimerParam_t *param);
extern void SystemTimerHeadDestory(SystemTimer_t **timer);
extern void SystemTimerNodeDestory(SystemTimer_t *timer);
extern void SystemTimerDestoryLinkListRecurse(SystemTimer_t **timer);
extern void SystemTimerDestory(SystemTimer_t **timer, SystemTimer_t *delete_timer);
extern void SystemTimerTailDestory(SystemTimer_t **timer);
extern void SystemTimerDestoryLinkList(SystemTimer_t **timer);
extern void SystemTimerStart(SystemTimer_t *timer);
extern void SystemTimerStop(SystemTimer_t *timer);
extern void SystemTimerUseEnd(SystemTimer_t *timer);
extern void SystemTimerStartWhole(SystemTimer_t *timer);
extern void SystemTimerStopWhole(SystemTimer_t *timer);
extern void SystemTimerUpdateValue(SystemTimer_t *timer);
extern void SystemTimerHandle(SystemTimer_t **timer);

#ifdef __cplusplus
}
#endif

#endif
